﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sern.ServiceImplementation
{
    public static class BindingSchemeHelper
    {
        public static Uri GetBaseUri(this BindingScheme bindingScheme, string hostName)
        {
            UriBuilder uriBUilder = new UriBuilder(
                bindingScheme.Scheme,
                hostName,
                bindingScheme.Port ?? -1
                );

            return uriBUilder.Uri;
        }

        public static Uri GetEndpointUri(this BindingScheme bindingScheme, string hostName)
        {
            string path = !string.IsNullOrWhiteSpace(bindingScheme.PathPrefix)
                              ? bindingScheme.PathPrefix + @"\" + bindingScheme.ClientType.ToString()
                              : bindingScheme.ClientType.ToString();

            UriBuilder uriBUilder = new UriBuilder(
                bindingScheme.Scheme,
                hostName,
                bindingScheme.Port ?? -1,
                path
            );

            return uriBUilder.Uri;
        }
    }
}
